<template>
  <el-table :data="tableData" style="padding: 15px" height="90%">
    <el-table-column
      v-for="(item, index) in optionsInfo"
      :width="item.width"
      :label="item.label"
      :prop="item.prop"
      :key="index"
      :show-overflow-tooltip="true"
    >
      <template #default="scope">
        <template v-if="item.prop === 'bh'" >
          {{scope.$index + 1 }}
        </template>
        <template v-else-if="item.prop === 'storageId'">
          {{ scope.$index + 1 }}
        </template>
        <template v-else-if="item.prop === 'id'">
          {{ scope.$index + 1 }}
        </template>

        <template v-if="item.prop === 'pic'">
          <el-image
              style="width: 120px; height: 120px"
              :src= "scope.row[item.prop]"
              fit="cover"
          />
        </template>
        <template v-else-if="item.prop === 'cptp'">
          <el-image
              style="width: 120px; height: 120px"
              :src="scope.row[item.prop]"
              fit="cover"
          />
        </template>
        <template v-else-if="item.prop === 'processPic'">
          <el-image
              style="width: 120px; height: 120px"
              :src="scope.row[item.prop]"
              fit="cover"
          />
        </template>
        <template v-else-if="item.prop === 'cdt'">
          <el-image
              style="width: 120px; height: 120px"
              :src="scope.row[item.prop]"
              fit="cover"
          />
        </template>
        <template v-else-if="item.prop === 'picture'">
          <el-image
              style="width: 120px; height: 120px"
              :src="scope.row[item.prop]"
              fit="cover"
          />
        </template>
        <template v-else-if="item.prop === 'certificateMaterial'">
          <el-image
              style="width: 120px; height: 120px"
              :src="scope.row[item.prop]"
              fit="cover"
          />
        </template>
      </template>
      <template #default="{ row }" v-if="item.prop === 'certificate'">
        <el-tag size="large">{{ row[item.prop] }}</el-tag>
      </template>
      <template #default="{ row }" v-if="item.prop === 'status'">
        <el-tag type="success" size="large" v-if="row[item.prop] === true" >
          <p>已上链</p>
        </el-tag>
        <el-tag type="warning" size="large" v-else-if="row[item.prop] === false">
          <p>未上链</p>
        </el-tag>
      </template>
      <template #default="{ row }" v-if="item.prop === 'action'">
        <el-row class="justify-items-auto justify-start">
          <el-tooltip content="编辑" placement="top">
            <el-button
                size="default"
                type="primary"
                :icon="Edit"
                @click="handleDialogValue(row)"
            ></el-button>
          </el-tooltip>
          <el-tooltip content="删除" placement="top">
            <el-button
                size="default"
                type="danger"
                :icon="Delete"
                @click="deleteInfo(row)"
            >
            </el-button>
          </el-tooltip>
        </el-row>
      </template>
      <template #default="{ row }" v-if="item.prop === 'cpaction'">
        <el-row class="justify-items-auto justify-start">
          <el-tooltip content="删除此条信息" placement="top">
            <el-button
                size="default"
                type="danger"
                :icon="Delete"
                @click="deleteInfo(row)"
            >
            </el-button>
          </el-tooltip>
        </el-row>
      </template>
      <template #default="{ row }" v-if="item.prop === 'upLink'">
        <el-row class="justify-items-auto justify-start">
          <el-tooltip content="查看上链信息" placement="top">
            <el-button
                size="default"
                :icon="View"
                @click="getLinkInfo(row)"
                v-if="row.status"
                color="#626aef"
            ></el-button>
            </el-tooltip>
          <el-tooltip content="是否决定上链" placement="top">
            <el-button
                size="default"
                type="success"
                :icon="Link"
                @click="isUpLink(row)"
                v-if="!row.status"
            ></el-button>
          </el-tooltip>
          <el-tooltip content="产品上链信息修改" placement="top">
            <el-button
                size="default"
                type="primary"
                :icon="Edit"
                @click="handleDialogValue(row)"
                v-if="!row.status"
            ></el-button>
          </el-tooltip>
        </el-row>
      </template>
    </el-table-column>
  </el-table>
</template>

<script setup>
import {Delete, Edit, Link, View} from "@element-plus/icons-vue";
import {ref} from "vue";
const props = defineProps(["tableData", "optionsInfo"]);
const emits = defineEmits([
  "handleDialogLandValue",
  "delLandInfo",

  "handleDialogProductValue",
  "delProductInfo",

  "handleDialogCgValue",
  "delCgInfo",

  "handleDialogUseValue",
  "delUseInfo",

  "handleDialogNsValue",
  "delNsInfo",

  "handleDialogIotValue",
  "delIotInfo",

  "handleDialogCpValue",
  "delCpInfo",

  "handleDialogJcValue",
  "delJcInfo",

  "handleDialogJgValue",
  "delJgInfo",

  "handleDialogStValue",
  "delStInfo",

  "handleDialogIsValue",
  "delIsInfo",

  "handleDialogOsValue",
  "delOsInfo",

  "handleDialogKhValue",
  "delKhInfo",

  "handleDialogJyValue",
  "delJyInfo",

  "handleDialogProEviValue" ,
  "delProEviInfo",
    "upLink",
    "linkInfo"
]);
const isUpLink = (row)=> {
  emits("upLink", row)
}
const getLinkInfo = (row)=> {
  emits("linkInfo", row)
}

const handleDialogValue = (row) => {
  if (row.detailaddress != null) {
    // console.log(row)
    emits("handleDialogLandValue", row);
  } else if (row.cpbzq != null) {
    // console.log(row)
    emits("handleDialogProductValue", row);
  } else if (row.ly != null) {
    // console.log(row)
    emits("handleDialogCgValue", row);
  } else if (row.syrq != null) {
    // console.log(row)
    emits("handleDialogUseValue", row);
  } else if (row.cdmc != null) {
    // console.log(row)
    emits("handleDialogNsValue", row);
  } else if (row.scfzr != null) {
    // console.log(row)
    emits("handleDialogCpValue", row);
  } else if (row.jcr != null) {
    // console.log(row)
    emits("handleDialogJcValue", row);
  } else if (row.fzr != null) {
    // console.log(row)
    emits("handleDialogJgValue", row);
  } else if (row.storageDh != null) {
    // console.log(row)
    emits("handleDialogStValue", row);
  } else if (row.inNumber != null) {
    // console.log(row)
    emits("handleDialogIsValue", row);
  } else if (row.outNumber != null) {
    // console.log(row)
    emits("handleDialogOsValue", row);
  } else if (row.clientSource != null) {
    // console.log(row)
    emits("handleDialogKhValue", row);
  } else if (row.name != null) {
    // console.log(row)
    emits("handleDialogJyValue", row);
  } else if (row.proIndex != null) {
    // console.log(row)
    emits("handleDialogProEviValue", row);
  } else if (row.ph != null) {
    // console.log(row)
    emits("handleDialogIotValue", row);
  }
};
const deleteInfo = (row) => {
  if (row.detailaddress != null) {
    // console.log(row)
    emits("delLandInfo", row);
  } else if (row.cpbzq != null) {
    // console.log(row)
    emits("delProductInfo", row);
  } else if (row.ly != null) {
    emits("delCgInfo", row);
  } else if (row.syrq != null) {
    emits("delUseInfo", row);
  } else if (row.cdmc != null) {
    emits("delNsInfo", row);
  } else if (row.ph != null) {
    emits("delIotInfo", row);
  } else if (row.scfzr != null) {
    // console.log(row)
    emits("delCpInfo", row);
  } else if (row.jcr != null) {
    // console.log(row)
    emits("delJcInfo", row);
  } else if (row.fzr != null) {
    // console.log(row)
    emits("delJgInfo", row);
  } else if (row.storageDh != null) {
    // console.log(row)
    emits("delStInfo", row);
  } else if (row.inNumber != null) {
    // console.log(row)
    emits("delIsInfo", row);
  } else if (row.outNumber != null) {
    // console.log(row)
    emits("delOsInfo", row);
  } else if (row.clientSource != null) {
    // console.log(row)
    emits("delKhInfo", row);
  } else if (row.name != null) {
    // console.log(row)
    emits("delJyInfo", row);
  } else if (row.proIndex != null) {
    // console.log(row)
    emits("delProEviInfo", row);
  }
};
</script>

<style scoped>
</style>


